/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  Navigator,
  Image,
  View,
  BackAndroid,
  Platform,
  Alert,
  AsyncStorage
} from 'react-native';

var MainTab = require("./MainTab");
var DeviceList = require("./DeviceList");
var PersonInfo = require("./PersonInfo");
var TabSetting = require("./TabSetting");
var ControlPage = require("./ControlPage");
var Setting = require("./Setting");
var FixPassword = require("./FixPassword");
var Login = require("./Login");

var Welcome = require("./Component/Welcome");
var Web = require("./Component/Web");
var About = require("./Component/About");
var Register = require("./Register");
var CollectArticle = require("./CollectArticle");
var MoreArticle = require("./MoreArticle");
var FeedBack = require("./FeedBack");
var Test = require("./Test");

var _navigator;


BackAndroid.addEventListener('hardwareBackPress', () => {
	if (_navigator && _navigator.getCurrentRoutes().length > 1) {
	    _navigator.pop();
	    return true;
	}else{
		Alert.alert(
            '提醒',
            '是否退出app',
            [
              	{text: '取消', onPress: () => {return true}},
              	{text: '确定', onPress: ()=>{
					BackAndroid.exitApp();
              	}}
            ]
		);
	}
	return true;
});
	
class Main extends Component {
	constructor() {  
		super();
  	}
	
	configureScenceAndroid(route) {
		return Navigator.SceneConfigs.FloatFromBottomAndroid;
	}
	
		/**
	 *配置跳转路由
	 */
	renderSceneAndroid(route, navigator) {
		_navigator = navigator;
		if(route.id === 'Welcome'){
			return(
				<Welcome navigator={navigator}/>
			);
		}else
		if(route.id === 'first') {
			return( 
				<MainTab navigator={navigator}/>
			);
		}else if(route.id === 'DeviceList'){
			return(
				<DeviceList navigator={navigator}/>
			);
		}else if(route.id === 'Web'){
			return(
				<Web navigator={navigator} url={route.url} articleid={route.articleid} {...route.params}/>
			);
		}else if(route.id === "TabSetting"){
			return(
				<TabSetting navigator={navigator}/>
			);
		}else if(route.id === "PersonInfo"){
			return(
				<PersonInfo navigator={navigator}/>
			);
		}else if(route.id === "ControlPage"){
			return(
				<ControlPage navigator={navigator} title={route.title} mode={route.mode} bleid={route.bleid}/>
			);
		}else if(route.id === "Login"){
			return(
				<Login navigator={navigator} />
			);
		}else if(route.id === "Setting"){
			return(
				<Setting navigator={navigator} />
			);
		}else if(route.id === "FixPassword"){
			return(
				<FixPassword navigator={navigator} />
			);
		}else if(route.id === "Register"){
			return(
				<Register navigator={navigator} />
			);
		}else if(route.id === "About"){
			return(
				<About navigator={navigator} />
			);
		}else if(route.id === "Welcome"){
			return(
				<Welcome navigator={navigator} />
			);
		}else if(route.id === "Test"){
			return(
				<Test />
			);
		}else if(route.id === "CollectArticle"){
			return(
				<CollectArticle navigator={navigator}/>
			);
		}else if(route.id === "MoreArticle"){
			return(
				<MoreArticle navigator={navigator} title={route.title} sort={route.sort}/>
			)
		}else if(route.id === "FeedBack"){
			return(
				<FeedBack navigator={navigator}/>
			)
		}
	}
	
  	render() {
  		var renderScene = this.renderSceneAndroid;
		var configureScence = this.configureScenceAndroid;
    	return (
      		<Navigator debugOverlay = {false} initialRoute = {{id: "Welcome",title:"智能按摩内衣"}}
			configureScence = {
				{
					configureScence
				}
			}
			renderScene = {
				renderScene
			}/>
    	);
  	}
}

const styles = StyleSheet.create({
   	container: {
    	flex: 1,
    	alignItems: 'center',
    	backgroundColor: '#F5FCFF',
  	},
  	checkbtn:{
  		backgroundColor: '#ff00ff',
  	},
  	top:{
  		height:80,
  	},
  	 tabIcon: {
        width: 30,
        height: 30,
        marginTop: -10.5
    },
});

module.exports = Main;